<%@ page pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://www.ld.com/shield/tags" prefix="shield"%>
<%@ page trimDirectiveWhitespaces="true" %>
<fmt:setLocale value="zh_CN"/>
<%-- 权限判断 --%>
<shield:permssion type="button">
<div >
	<!-- t改为shieldTarget，且为jQuery选择器形式 -->
    <form action="${ctxPathA}/system/dbbackup/search" method="post" shieldTarget="#searchResult" class="searchForm ">
    	<shield:token/>
    	  <div class="search-box">
	            	<label>说明：</label>
         		<span class="tips">快速备份是进行全库备份，如果需要更多的备份项，可以点击高级数据库备份进行备份设置，进行备份</span>
    		</div>
        <div class="search-box">
            <span class="search-i">
             <span class="search-i"><b>连接：</b>
             <select id="dbConnId" name="dbConnId" >
            	<option value="0">本项目库</option>
    <c:forEach var="dbset" items="${dbsets }">
    			<option value="${dbset.id}">${dbset.dbSetName }</option>
    </c:forEach>
            </select>
             </span>
	             <input class="submit" type="button" onclick="backup()" name="doSearch" value="快速备份">
					<!-- 需要弹出的元素上增加样式shieldDialog注册，定义属性data-url表示连接，viewTitle为弹出框的标题 -->
					<a data-url="${ctxPathA}/system/dbbackup/toDbbackupSet" class="shieldDialog" viewTitle="高级数据库备份" viewWidth="800">
					  <input class="addBaseTable" type="button" name="addBaseTable" value="高级数据库备份">
					</a>
			<input class="submit" type="submit"  value="刷新">
            </span>
        </div>
        <div id="searchResult"></div>
    </form>
</div>
</shield:permssion>
<script type="text/javascript">
var time;
function backup()
{
	ShieldJS.confirm("消息", "确定要备份数据库吗", function(){
		
		 var url = "${ctxPathA}/system/dbbackup/quickBackup";
			var postData = { "dbConnId":""+$("#dbConnId").val()+""};                 
			$.ajax({
		    		type: "POST",
		     		url: url,
		     		data:postData,
		     		beforeSend:function(xhr){
		     			ShieldJS.openDialog("${ctxPathA}/system/dbbackup/process", {}, function (ele, dialog, index) {
		     				 time=setInterval(function(){
		     					setProcess(ele);
		     				}, 100);
		     			});
		     		},
		     		success: function(mg){     
		             console.log(mg);
		          }
		    });	

		
	})
	

}
function setProcess(ele){ 
	$.ajax({
		type: "POST",
 		url: "${ctxPathA}/system/dbbackup/getProcess",
 		data:{type:0},
 		success: function(mg){     
         console.log(mg);
         if(mg.success&&mg.data)
       	 {
       	     ele.find("#processbar").val(mg.data.percent);
             ele.find("#processvalue").text(mg.data.content);
             ele.find("#backnumvalue").text("("+mg.data.backnum+")");
             if(mg.data.backstatus==1){
            	 $(".searchForm").submit();
           	   clearInterval(time);
           	 }else if(mg.data.backstatus==-1){
             	   clearInterval(time);
             }
       	 }
       
      }
   }); 	
	
} 


</script>